import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import("@/pages/Home");
const Register = () => import("@/pages/Register");
const Login = () => import("@/pages/Login");
const Search = () => import("@/pages/Search");
const Detail = () => import("@/pages/Detail");
const AddCartSuccess = () => import("@/pages/AddCartSuccess");
const ShopCart = () => import('@/pages/ShopCart')

//重写push
const lastPush = VueRouter.prototype.push

VueRouter.prototype.push = function (location,onComplete = () => {}, onAbort = () => {}) {
  return lastPush.call(this,location, onComplete, onAbort)
}

Vue.use(VueRouter)

const routes = [
  {
    path: "/home",
    name:"home",
    component: Home,
  },
  {
    path: "/login",
    name:"login",
    component: Login,
    meta: { footerIsHidden: true },
  },
  {
    path: "/register",
    name:"register",
    component: Register,
    meta: { footerIsHidden: true },
  },
  {
    name: "search",
    path: "/search/:keyword?",
    component: Search,

  },
  {
    path: "/detail/:skuId",
    name:"detail",
    component: Detail,
  },
  {
    path: "/addcartsuccess",
    name:"addcartsuccess",
    component: AddCartSuccess,
  },
  {
    path: "/shopcart",
    name:"shopcart",
    component: ShopCart,
  },
  {
    path: "/",
    redirect: "/home"
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(){
    return{
      x:0,
      y:0
    }
  }
})

export default router
